package com.zito.health.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zito.health.common.annotations.ResponseResult;
import com.zito.health.common.result.PlatformResult;
import com.zito.health.common.result.VerifyResult;
import com.zito.health.entity.ItemFeasibility;
import com.zito.health.entity.ItemFeasibilityExpenses;
import com.zito.health.service.ItemFeasibilityExpensesService;
import com.zito.health.service.ItemFeasibilityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 项目可行性报告表-经费支出预算
 */
@Slf4j
@RestController
@RequestMapping("/item/feasibilityExpenses")
public class ItemFeasibilityExpensesController {

    @Autowired
    private ItemFeasibilityExpensesService itemFeasibilityExpensesService;

    @PostMapping("/save")
    public PlatformResult save(String jsonParam){
        List<ItemFeasibilityExpenses> items = JSONArray.parseArray(jsonParam, ItemFeasibilityExpenses.class);
        for(ItemFeasibilityExpenses item:items){
            if(item.getId() == null){
                itemFeasibilityExpensesService.save(item);
            }else{
                itemFeasibilityExpensesService.update(item);
            }

        }
        return  PlatformResult.success();
    }

    @PostMapping("/update")
    public PlatformResult update(ItemFeasibilityExpenses item){
        itemFeasibilityExpensesService.update(item);
        return  PlatformResult.success();
    }

    @PostMapping("/query")
    public PlatformResult query(ItemFeasibilityExpenses item){
        return PlatformResult.success(itemFeasibilityExpensesService.query(item));
    }

}
